///////////////////////////////////////////////////////////////////
// Student name:Jon Hersack and Caleb Reinking
// Course: COSC 3403
// Assignment: #7 - Initial Software Construction
// File name:Hand.java
// Purpose: Provides a vector of Cards to be used by the player class
// Assumptions:none known
// Limitations:none known
// Development Computer:Intel core2 duo 2.67Ghz
// Operating System: windows
// Integrated Development Environment (IDE): netbeans 6.5
// Compiler: Javac: java 1.6.0_13
///////////////////////////////////////////////////////////////////

import java.util.*;

public class Hand
{
    final int MAX_CARDS = 7;
    Vector<Card> cardVect;

    //constructors
    Hand()
    {//sets up empty hand vector for 7 cards
        cardVect = new Vector<Card>(MAX_CARDS);
    }//end Hand()


    //methods
    //########################################
    Boolean isFull()
    {

        if(cardVect.size()==cardVect.capacity())
        return true;
        else return false;

    }//end is Full

    //########################################
    Card getCard(int index)
    {
        Card returnedCard = cardVect.elementAt(index);
        return returnedCard;
    }//end getCard

    //########################################
    void clearHand()
    {
        cardVect.clear();
    }//end clearHAnd

    //########################################
    Boolean isEmpty()
    {
        return cardVect.isEmpty();
    }//end is Empty

    //########################################
    void addCard(Card newCard)
    {
        if(!isFull())
        {
            cardVect.add(newCard);
        }//end if
    }//end addCard

        //########################################
    Card removeCard(int index)
    {
        if(!isEmpty())
        {
            Card returnedCard = cardVect.elementAt(index);
            cardVect.remove(index);
             return returnedCard;
        }//end if
        else
        return null;
    }//end addCard

        //########################################
    int size()
    {
        return cardVect.size();
    }//end addCard

    //########################################
    int indexOfCardById(int typeID)
    {
        Card checkedCard = new Card(typeID);
        Card tempCard;
        for(int i=0; i < cardVect.size(); i++)
        {
            tempCard = getCard(i);
            if(tempCard.compareTo(checkedCard) == 1)
            { return i;}//end if
        }//end for
        
        return -1;
    }//end indexOfCardById

    //########################################
    int indexOfCardByType(String cardType)
    {
        for(int i=0; i < cardVect.size(); i++)
        {
            if(getCard(i).toStringRep().get(0).compareTo(cardType) == 0)
            { return i;}//end if
        }//end for

        return -1;
    }//end indexOfCardByType

    //########################################
    int indexOfCardBySubType(String cardType)
    {
        for(int i=0; i < cardVect.size(); i++)
        {
            if(getCard(i).toStringRep().get(1).compareTo(cardType) == 0)
            { return i;}//end if
        }//end for

        return -1;
    }//end indexOfCardByType

    
     //self test main
     //##################################
    public static void main(String args[])
    {
        Hand testHand = new Hand();

        Card card0 = new Card(5);
        Card card1 = new Card(9);
        Card card2 = new Card(1);
        Card card3 = new Card(18);
        Card card4 = new Card(16);
        Card card5 = new Card(15);
        Card card6 = new Card(2);

        //test empty
        System.out.print("hand is empty: ");
        System.out.println(testHand.isEmpty());

        //test add
        testHand.cardVect.add(card0);
        testHand.cardVect.add(card1);
        testHand.cardVect.add(card2);

        System.out.print("num cards: ");//shoudl get 3
        System.out.println(testHand.size());
        //test empty
        System.out.print("hand is empty: ");
        System.out.println(testHand.isEmpty());

        //test is full
        System.out.print("hand is full: ");
        System.out.println(testHand.isFull());

        //test index of
        System.out.print("card type3 located at: ");
        System.out.println(testHand.indexOfCardById(3));

        System.out.print("card type5 located at: ");
        System.out.println(testHand.indexOfCardById(5));//should return 0

        testHand.cardVect.add(card3);
        testHand.cardVect.add(card4);
        testHand.cardVect.add(card5);
        testHand.cardVect.add(card6);

        //test is full
        System.out.print("hand is full: ");
        System.out.println(testHand.isFull());

        System.out.print("num cards: ");//shoudl get 7
        System.out.println(testHand.size());

        Card returnedCard = testHand.getCard(5);
        Vector strings = returnedCard.toStringRep();

        System.out.println(strings.get(0));
        System.out.println(strings.get(1));
        System.out.println(strings.get(2));

        //test reomove card
        testHand.removeCard(5);

        returnedCard = testHand.getCard(5);
        strings = returnedCard.toStringRep();

        System.out.println(strings.get(0));
        System.out.println(strings.get(1));
        System.out.println(strings.get(2));
        System.out.print("num cards: ");//shoudl get 6
        System.out.println(testHand.size());

        System.out.print("hand is full: ");
        System.out.println(testHand.isFull());

        System.exit(0);
    }//end test main

}//end class Hand
